package service

import (
	"goproject/src/common"
	"goproject/src/globalvariable"
	"goproject/src/mapper"
	"goproject/src/model"
)

// 查询所有数据
func GetOrderItemList() []model.DesOrderItem {
	db := globalvariable.MysqlDB
	return mapper.GetOrderItemList(db)
}

// 根据id删除数据
func DeleteItemById(id string) {
	db := globalvariable.MysqlDB
	mapper.DeleteItemById(db, id)
}

// 单条数据更新
func UpdateDesItem(item model.DesOrderItem) {
	db := globalvariable.MysqlDB
	mapper.UpdateDesItem(db, item)
}

// 单条数据新增
func SaveDesItem(item model.DesOrderItem) {
	db := globalvariable.MysqlDB
	item.Id = common.GetUUID()
	mapper.SaveDesItem(db, item)
}

// 批量保存数据
func BatchSaveDesItems(items []model.DesOrderItem) {
	db := globalvariable.MysqlDB
	var length int = len(items)
	for i := 0; i < length; i++ {
		//通过uuid生成主键
		items[i].Id = common.GetUUID()
	}
	mapper.BatchSaveDesItems(db, items)
}
